<template>
    <div class="login-content">
        <div class="form">
            <div class="login-pic">
                <img class="logo" src="@/assets/logo.png" alt="">
            </div>
            <el-form ref="form" :model="formData" :rules="rules">
                <el-form-item prop="username">
                    <el-input v-model="formData.username" prefix-icon="el-icon-user-solid" placeholder="请输入用户名"></el-input>
                </el-form-item>
                <el-form-item prop="password">
                    <el-input type="password" v-model="formData.password" prefix-icon="el-icon-lock" placeholder="请输入用密码"></el-input>
                </el-form-item>
                <el-form-item style="float: right;">
                    <el-button type="primary" @click="submitForm">登录</el-button>
                    <el-button>重置</el-button>
                </el-form-item>
            </el-form>
        </div>
    </div>
</template>

<script>
export default {
  name: 'ShoppingIndex',

  data () {
    return {
      formData: {
        username: 'admin',
        password: '123456'
      },
      rules: {
        username: [
          { required: true, message: '请输入用户名', trigger: 'blur' },
          { pattern: /^[a-z]+$/i, message: '用户名只能是小写字母', trigger: 'blur' },
          { min: 5, max: 10, message: '长度在 5 到 10 个字符', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' },
          { min: 5, max: 10, message: '长度在 5 到 10 个字符', trigger: 'blur' }
        ]
      }
    }
  },

  mounted () {

  },

  methods: {
    submitForm () {
      this.$refs.form.validate((valid) => {
        if (valid) {
          this.$store.dispatch('login/getUserLogin', this.formData)
        } else {
          console.log('error submit!!')
          return false
        }
      })
    }
  }
}
</script>

<style lang="less" scoped>
.login-content {
    width: 100vw;
    height: 100vh;
    background-color: #2B4B6B;
    position: relative;
    .form {
        .logo {
            width: 100%;
            height: 100%;
            border-radius: 50%;
            overflow: hidden;
        }
        width: 500px;
        height: 300px;
        background-color: #fff;
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%,-50%);
        padding: 20px;
        .login-pic {
            width: 150px;
            height: 150px;
            border-radius: 50%;
            background-color: #EEEEEE;
            position: absolute;
            border: 10px solid #fff;
            top: -75px;
            left: 50%;
            transform: translateX(-50%);
            box-shadow: 0 0 10px #ddd;
        }
        .el-form {
            margin-top: 100px;
        }
    }
}
</style>
